package cn.stylefeng.guns.modular.pandian.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.inventory.model.result.MoveDiskDetailedResult;
import cn.stylefeng.guns.modular.pandian.entity.PandianChoupanDetailed;
import cn.stylefeng.guns.modular.pandian.mapper.PandianChoupanDetailedMapper;
import cn.stylefeng.guns.modular.pandian.model.params.PandianChoupanDetailedParam;
import cn.stylefeng.guns.modular.pandian.model.result.PandianChoupanDetailedResult;
import  cn.stylefeng.guns.modular.pandian.service.PandianChoupanDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 抽盘明细表 服务实现类
 */
@Service
public class PandianChoupanDetailedServiceImpl extends ServiceImpl<PandianChoupanDetailedMapper, PandianChoupanDetailed> implements PandianChoupanDetailedService {

    @Override
    public void add(PandianChoupanDetailedParam param){
        PandianChoupanDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PandianChoupanDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PandianChoupanDetailedParam param){
        PandianChoupanDetailed oldEntity = getOldEntity(param);
        PandianChoupanDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PandianChoupanDetailedResult findBySpec(PandianChoupanDetailedParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<PandianChoupanDetailedResult> findListBySpec(PandianChoupanDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(PandianChoupanDetailedParam param,String condition, Long deptId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, deptId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(PandianChoupanDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PandianChoupanDetailed getOldEntity(PandianChoupanDetailedParam param) {
        return this.getById(getKey(param));
    }

    private PandianChoupanDetailed getEntity(PandianChoupanDetailedParam param) {
        PandianChoupanDetailed entity = new PandianChoupanDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<PandianChoupanDetailedResult> historyDetailedList(PandianChoupanDetailedParam moveDiskDetailedParam) {
		return this.baseMapper.historyDetailedList(moveDiskDetailedParam);
	}

	@Override
	public List<PandianChoupanDetailedResult> findPositionList(PandianChoupanDetailedParam moveDiskDetailedParam) {
		return this.baseMapper.findPositionList(moveDiskDetailedParam);
	}

	@Override
	public LayuiPageInfo deleteList(PandianChoupanDetailedParam moveDiskDetailedParam, String condition, Long deptId,Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.deleteList(pageContext, moveDiskDetailedParam,condition,deptId, operateId);
        return LayuiPageFactory.createPageInfo(page);
	}

	@Override
	public List<PandianChoupanDetailedResult> appabnormalliststaylist(PandianChoupanDetailedParam param, Long deptId,Long operateId) {
		return this.baseMapper.appabnormalliststaylist(param,deptId,operateId);
	}

	@Override
	public PandianChoupanDetailedResult findBySpec2(PandianChoupanDetailedParam param) {
		return this.baseMapper.findBySpec2(param);
	}

}
